package com.china.produce.bdregistrar;

import com.china.produce.pojo.Book;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 实现importBeanDefinitionRegistrar,这个类要导入才会生效
 *
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2023/5/3
 */
public class BookImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {


        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(Book.class)
                .addPropertyValue("id", 100l)
                .addPropertyValue("name", "你好")
                .getBeanDefinition();

        registry.registerBeanDefinition("books", beanDefinition);
    }
}
